package com.sinheldrin.musicplayer.settings
{
	import com.sinheldrin.musicplayer.reader.XmlReader;
	import com.sinheldrin.musicplayer.writer.XmlWriter;
	
	import flash.filesystem.File;
	
	import spark.components.WindowedApplication;

	public class SettingsController
	{
		private static const FILENAME:String = "settings.xml";
		
		public function SettingsController()
		{
			_model = new SettingsModel();
		}
		
		private var _model:SettingsModel = null;
		public function get model():SettingsModel
		{
			return _model;
		}
		
		public function load():void
		{
			var reader:XmlReader = new XmlReader();
			reader.readSettings(model, File.applicationStorageDirectory.resolvePath(FILENAME));
		}
		
		public function save():void
		{
			var writer:XmlWriter = new XmlWriter();
			writer.writeSettings(model, File.applicationStorageDirectory, FILENAME);
		}
		
		public function apply(app:WindowedApplication):void
		{
			app.nativeWindow.x = model.applicationXPosition;
			app.nativeWindow.y = model.applicationYPosition;
		}
		
		public function retrieve(app:WindowedApplication):void
		{
			model.applicationXPosition = app.nativeWindow.x;
			model.applicationYPosition = app.nativeWindow.y;
		}
	}
}